/*
 moxl - Modular XML Library
 Copyright (c) 2007, Malcolm Sparks

 This program is free software; you can redistribute it and/or
 modify it under the terms of the GNU General Public License
 as published by the Free Software Foundation; either version 2
 of the License, or (at your option) any later version.

 This program is distributed in the hope that it will be useful,
 but WITHOUT ANY WARRANTY; without even the implied warranty of
 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 GNU General Public License for more details.

 You should have received a copy of the GNU General Public License
 along with this program; if not, write to the Free Software
 Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, USA.
 */
package moxl.reader;

public class Location implements Cloneable
{
	/**
	 * The amount of columns advanced when a tab is seen.
	 */
	public final static int TAB_WIDTH = 8;

	private long line;
	private int column;

	public Location()
	{
		line = 1;
		resetColumn();
	}

	public long getLine()
	{
		return line;
	}

	public int getColumn()
	{
		return column;
	}

	@Override
	public Object clone() throws CloneNotSupportedException
	{
		Location res = (Location) super.clone();
		res.line = line;
		res.column = column;
		return res;
	}

	@Override
	public String toString()
	{
		return "line " + line + ", column " + column;
	}

	public void advanceColumn()
	{
		column++;
	}

	public void advanceLine()
	{
		line++;
		resetColumn();
	}

	private void resetColumn()
	{
		column = 0;
	}

	public void advanceColumnByTab()
	{
		column += TAB_WIDTH;
	}
}
